<?php

class DigUser_Service_User
{
    public static function current()
    {
        $auth = Zend_Auth::getInstance();

        if($auth->hasIdentity()) {
            return $auth->getIdentity (); 
        }
    }

    public static function getUserById($id) {
        $model = new DigUser_Model_Account();
        return $model->find($id)->current();
    }
    
    public static function roles($verbose = false)
    {
        $roles = Dig_Service_Core::getInstance()->getAcl()->getRegisteredRoles();
        if($verbose) {
            return $roles;
        } else {
            return array_keys($roles);
        }
    }

    public static function allow($role, $module, $controller = null, $action = null) {
//        Zend_Debug::dump(func_get_args());
        $acl = Dig_Service_Core::getInstance()->getAcl();
        $acl->addResource($module, $controller, $action);
        $acl->allow($role,$module, $controller, $action);
    }

    public static function deny($role, $module, $controller = null, $action = null) {
        //Zend_Debug::dump(func_get_args());
        $acl = Dig_Service_Core::getInstance()->getAcl();
        $acl->addResource($module, $controller, $action);
        $acl->deny($role,$module, $controller, $action);
    }

    public static function isAllowed($role, $module, $controller = null, $action = null) {
        $acl = Dig_Service_Core::getInstance()->getAcl();
        return $acl->isAllowed($role,$module, $controller, $action);
    }

    public static function urlIsAllowed($role, $url)
    {
        $acl = Dig_Service_Core::getInstance()->getAcl();
        return $acl->urlIsAllowed($role, $url);
    }
}
?>